package com.mpgame.database.mysql.mapper.game;

import com.mpgame.database.mysql.mapper.BaseMapper;
import com.mpgame.database.mysql.model.game.Titles;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface TitlesMapper extends BaseMapper<Titles> {
    
    @Insert("INSERT INTO titles (name, color, icon_url) VALUES (#{name}, #{color}, #{iconUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Titles titles);

    @Select("SELECT * FROM titles WHERE id = #{id}")
    Titles selectById(@Param("id") int id);

    @Select("SELECT * FROM titles WHERE name = #{name}")
    Titles selectByName(@Param("name") String name);

    @Select("SELECT * FROM titles")
    List<Titles> selectAll();

    @Update("UPDATE titles SET name = #{name}, color = #{color}, icon_url = #{iconUrl} WHERE id = #{id}")
    int updateById(Titles titles);
}
